package com.angel.crowd.controller;

import com.angel.crowd.api.MySQLRemoteService;
import com.angel.crowd.constant.CrowdConstant;
import com.angel.crowd.entity.vo.PortalTypeVO;
import com.angel.crowd.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author yuzhen
 * @create 2020-05-10 17:14
 */
@Controller
public class PortalController {

    @Autowired
    private MySQLRemoteService mySQLRemoteService;

    @RequestMapping(value = "/")
    public String showPortalPage(Model model){
        // 1、调用MySQLRemoteService提供的方法查询首页要显示的数据
        ResultEntity<List<PortalTypeVO>> resultEntity = mySQLRemoteService.getPortalTypeProjectDataRemote();
        // 2.检查查询结果
        String result = resultEntity.getResult();
        if(ResultEntity.SUCCESS.equals(result)){
            // 3.获取查询结果数据
            List<PortalTypeVO> list  = resultEntity.getData();
            model.addAttribute(CrowdConstant.ATTR_NAME_PORTAL_DATA, list);
        }
        return "portal";
    }
}
